package com.dai.zhenfujin.my.activity;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dai.zhenfujin.AccountPasswordActivity;
import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.base.BaseActivity;
import com.dai.zhenfujin.utils.SPUtils;
import com.dai.zhenfujin.utils.UIUtils;
import com.dai.zhenfujin.view.CommonDialog;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.orhanobut.logger.Logger;

import java.util.Map;


/**
 * 设置页面
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener{

    private TextView tvName;
    private RelativeLayout rlAccount,rlMessage,rlBlacklist,rlAboutUs,rlBlack,rl_platform,rl_huancun;
    private ImageView imageView;
    private Button btDropOut;
    private String key1;
    private String key2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
    }

    private void initView() {
        imageView = findViewById(R.id.title_imageview);
        tvName = findViewById(R.id.title_textview);
        rlAccount = findViewById(R.id.setting_account_security);
        rlMessage = findViewById(R.id.setting_message);
        rlBlacklist = findViewById(R.id.setting_blacklist);
        rlAboutUs = findViewById(R.id.setting_about_us);
        rlBlack = findViewById(R.id.setting_my_black);
        rl_platform = findViewById(R.id.rl_platform);
        rl_huancun = findViewById(R.id.rl_huancun);

        btDropOut= findViewById(R.id.setting_drop_out);
        btDropOut.setOnClickListener(this);
        imageView.setOnClickListener(this);
        rlAccount.setOnClickListener(this);
        rlMessage.setOnClickListener(this);
        rlBlacklist.setOnClickListener(this);
        rlAboutUs.setOnClickListener(this);
        rlBlack.setOnClickListener(this);
        rl_platform.setOnClickListener(this);
        rl_huancun.setOnClickListener(this);
        tvName.setText("设置");

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.title_imageview://返回
                finish();
                break;
            case R.id.setting_account_security://关于我们
              //  Intent security = new Intent(this,SecurityActivity.class);
                Intent security = new Intent(this,AboutWeActivity.class);
                startActivity(security);
                break;
            case R.id.setting_blacklist://隐私协议
              //  Intent security = new Intent(this,SecurityActivity.class);
                Intent intent = new Intent(this,AboutAgreementActivity.class);
                intent.putExtra("type",1);
                startActivity(intent);
                break;
            case R.id.setting_message:// 用户协议
              //  Intent security = new Intent(this,SecurityActivity.class);
                Intent meg = new Intent(this,AboutAgreementActivity.class);
                meg.putExtra("type",0);
                startActivity(meg);
                break;
            case R.id.rl_platform:// 平台规则
              //  Intent security = new Intent(this,SecurityActivity.class);
                Intent platform = new Intent(this,AboutAgreementActivity.class);
                platform.putExtra("type",2);
                startActivity(platform);
                break;
            case R.id.rl_huancun:// 清理
                new CommonDialog(this, R.style.dialog, false, "确认清理缓存吗", (dialog, confirm) -> {
                    if (confirm) {
                        UIUtils.showToastSafe("清理成功");
                    }
                    dialog.dismiss();
                }).show();

                break;

            case R.id.setting_my_black://黑名单
                Intent intent2 = new Intent(this,BlackActivity.class);
                startActivity(intent2);
                break;
            case R.id.setting_about_us://意见反馈
                Intent intent3 = new Intent(this,FeedbackActivity.class);
                startActivity(intent3);
                break;
            case R.id.setting_drop_out://退出
                EMClient.getInstance().logout(true, new EMCallBack() {
                    @Override
                    public void onSuccess() {
                        // TODO Auto-generated method stub
                        SettingActivity.this.runOnUiThread(() -> {
                            //SPUtils.clear(SettingActivity.this);
                             SPUtils.put(SettingActivity.this,"login",false);
                           // SPUtils.put(SettingActivity.this,"welcome",false);
                            SPUtils.put(SettingActivity.this,Constants.TOKEN,"");
                            Intent intent = new Intent(SettingActivity.this, AccountPasswordActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                            finish();
                        });
                    }

                    @Override
                    public void onProgress(int progress, String status) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError(int code, String message) {
                        // TODO Auto-generated method stub

                    }
                });
                break;
        }
    }
}
